package com.lsk.mytuan.entity;

import com.lsk.mytuan.util.Storageable;
import static com.lsk.mytuan.util.FloatCalc.*;

public class Order extends Storageable {
    private int id;
    private Item item;
    private int count;
    private float total;
    private int storeId;
    private String state;

    private static int idCounter = 0;

    public Order (Item item, int count) {
        this.id = ++idCounter;
        this.item = item;
        this.count = count;
        this.total = fmul(item.getPrice(), count);
        this.state = "NOTPAID";
        this.storeId = item.getStoreId();
    }

    public String getState () {
        return this.state;
    }

    public float getTotal () {
        return this.total;
    }

    @Override
    public int getId() {
        return this.id;
    }

    public void pay () {
        this.state = "PAID";
        Store store = (Store) Store.get(this.storeId);
        store.addMoney(this.total);
        this.item.increaseSales(this.count);
    }

    public void setState (String state) {
        this.state = state;
    }

    @Override
    public String toString() {
        String result = "";
        result += this.id;
        result += "     ";
        result += this.item.getName();
        result += "     ";
        result += this.count;
        result += "     ";
        result += this.total;
        result += "     ";
        result += this.state;
        return result;
    }
}
